<?php
/**
 * Application level Controller
 *
 * This file is application-wide controller file. You can put all
 * application-wide controller-related methods here.
 *
 * PHP versions 4 and 5
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       cake
 * @subpackage    cake.app
 * @since         CakePHP(tm) v 0.2.9
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */

/**
 * Application Controller
 *
 * Add your application-wide methods in the class below, your controllers
 * will inherit them.
 *
 * @package       cake
 * @subpackage    cake.app
 */
class AppController extends Controller {
	var $components = array('Auth', 'Session');
	
	function beforeFilter() {
		//$this->Auth->allow('index', 'view');
		$this->Auth->authError = 'Please login to view this page.';
		$this->Auth->loginError = 'Incorrect username or password.';
		$this->Auth->loginRedirect = array('controller'=>'evaluations', 'action'=>'index');
		$this->Auth->logoutRedirect = array('controller'=>'evaluations', 'action'=>'index');
		
		$this->set('admin', $this->_isAdmin());
		$this->set('wimi', $this->_isWimi());
		$this->set('logged_in', $this->_loggedIn());
		$this->set('users_name', $this->_usersName());
	}
	
	function _isAdmin () {
		$admin = FALSE;
		if ($this->Auth->user('roles') == 'admin') {
			$admin = TRUE;
		}
		return $admin;
	}
	
	function _isWimi () {
		$wimi = FALSE;
		if ($this->Auth->user('roles') == 'wimi') {
			$wimi = TRUE;
		}
		return $wimi;
	}
	
	function _loggedIn () {
		$logged_in = FALSE;
		if ($this->Auth->user()) {
			$logged_in = TRUE;
		}
		return $logged_in;
	}
	
	function _usersName() {
		$users_name = NULL;
		if ($this->Auth->user()) {
			$users_name = $this->Auth->user('name');
		}
		return $users_name;
	}
}
